<?php


namespace app\http;
use Swoole\Server;
use Swoole\Websocket\Frame;
use Swoole\WebSocket\Server as WebsocketServer;
use think\Config;
use think\Container;
use think\Request;
use think\swoole\contract\websocket\HandlerInterface;

class WebsocketEvent {
    public $websocket = null;

    public function __construct(Container $container) {
        $this->websocket = $container->make(\think\swoole\Websocket::class);
    }
    /**
     * 事件监听处理
     *
     * @return mixed
     */
    public function handle($event) {
        echo "Event\n";
        $func = $event->type; // 要调用的方法
        if (!method_exists($this, $func)) {
            $this->websocket->emit('testcallback', ['msg'=> $func.':方法不存在']);
        } else {
            $this->$func($event);
        }
    }

    public function send($data){
        echo 1;
    }
}